package me.pplay.playtalk.view;

import me.pplay.playtalk.R;
import me.pplay.playtalk.protocol.DataCallBack;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DialogView extends FrameLayout{
	private Context mContext;
	private View view;
	private LinearLayout layout_b, layout_c, layout_1, layout_2, layout_3, layout_4, layout_5;
	private ImageView image_1, image_2, image_3, image_4, image_5;
	private TextView tv_1, tv_2, tv_3, tv_4, tv_5;
	
	private DataCallBack callback;
	
	public DialogView(Context context) {
		super(context);
		this.mContext = context;
		initViews();
		this.addView(view);
	}

	
	private void initViews(){
		view 			= LayoutInflater.from(mContext).inflate(R.layout.layout_menu, null);
		layout_b    	= (LinearLayout)view.findViewById(R.id.layout_b);
		layout_c   	 	= (LinearLayout)view.findViewById(R.id.layout_c);
		layout_1    	= (LinearLayout)view.findViewById(R.id.layout_1);
		layout_2    	= (LinearLayout)view.findViewById(R.id.layout_2);
		layout_3    	= (LinearLayout)view.findViewById(R.id.layout_3);
		layout_4    	= (LinearLayout)view.findViewById(R.id.layout_4);
		layout_5    	= (LinearLayout)view.findViewById(R.id.layout_5);
		image_1			= (ImageView)view.findViewById(R.id.image_1);
		image_2			= (ImageView)view.findViewById(R.id.image_2);
		image_3			= (ImageView)view.findViewById(R.id.image_3);
		image_4			= (ImageView)view.findViewById(R.id.image_4);
		image_5			= (ImageView)view.findViewById(R.id.image_5);
		tv_1			= (TextView)view.findViewById(R.id.tv_1);
		tv_2			= (TextView)view.findViewById(R.id.tv_2);
		tv_3			= (TextView)view.findViewById(R.id.tv_3);
		tv_4			= (TextView)view.findViewById(R.id.tv_4);
		tv_5			= (TextView)view.findViewById(R.id.tv_5);
	}
	
	public void setDatas(int[] menu_drawableIds, String[] menu_titles, DataCallBack callback){
		this.callback	= callback;
		if(menu_titles.length == 2){
			layout_b.setVisibility(View.GONE);
			layout_c.setVisibility(View.GONE);
		}else if(menu_titles.length == 4){
			layout_c.setVisibility(View.GONE);
		}
		
		for (int i = 0; i < menu_titles.length; i++) {
			switch (i) {
			case 0:
				image_1.setBackgroundResource(menu_drawableIds[i]);
				tv_1.setText(menu_titles[i]);
				layout_1.setOnClickListener(new ClickListener(0));
				break;
			case 1:
				image_2.setBackgroundResource(menu_drawableIds[i]);
				tv_2.setText(menu_titles[i]);
				layout_2.setOnClickListener(new ClickListener(1));
				break;
			case 2:
				image_3.setBackgroundResource(menu_drawableIds[i]);
				tv_3.setText(menu_titles[i]);
				layout_3.setOnClickListener(new ClickListener(2));
				break;
			case 3:
				image_4.setBackgroundResource(menu_drawableIds[i]);
				tv_4.setText(menu_titles[i]);
				layout_4.setOnClickListener(new ClickListener(3));
				break;
			case 4:
				image_5.setBackgroundResource(menu_drawableIds[i]);
				tv_5.setText(menu_titles[i]);
				layout_5.setOnClickListener(new ClickListener(4));
				break;
			}
			
		}
	}
	
	class ClickListener implements OnClickListener{
		private int position = 0;
		public ClickListener(int index){
			position = index;
		}

		@Override
		public void onClick(View v) {
			callback.Callback(position, null, null);
		}
	}
	
}
